package com.cbh.amadeus.common.handler;

import com.cbh.amadeus.common.exception.ProtocolMagicMatchException;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;

/**
 * @author ChenBiHui
 * @date 2025/5/17
 */
@Slf4j
public class ExceptionHandler extends ChannelInboundHandlerAdapter {

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        if (cause instanceof ProtocolMagicMatchException) {
            log.error(cause.getMessage(), cause);
            return;
        }
        if (cause instanceof IOException) {
            log.error(cause.getMessage(), cause);
            return;
        }
        super.exceptionCaught(ctx, cause);
    }
}
